<?php

namespace app\modules\weixin\controllers;

use app\common\components\BaseWebController;
use app\common\service\UrlService;
use app\common\service\weixin\RequestService;

class MenuController extends BaseWebController
{

    public function actionSet()
    {
        $menu = [
            "button" => [
                [
                    "name" => "商城",
                    "type" => "view",
                    "url" => UrlService::buildCustomerUrl("/default/index")
                ],
                [
                    "name" => "后台",
                    "type" => "view",
                    "url" => UrlService::buildIndexUrl("/")
                ]
            ]
        ];

        $config = \Yii::$app->params['weixin'];
        RequestService::set($config['appid'], $config['appsecret'], $config['token']);

        $access_token = RequestService::getAccessToken();

        if ($access_token) {
            $url = "menu/create?access_token={$access_token}";
            $ret = RequestService::send($url, json_encode($menu, JSON_UNESCAPED_UNICODE), 'POST');
            var_dump($ret);
        }

    }
}
